package net.magicalcloud.magicalcloud.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import net.magicalcloud.magicalcloud.base.BaseViewHolder;
import net.magicalcloud.magicalcloud.entity.Shares;
import net.magicalcloud.magicalcloud.listener.OnRecyclerViewListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/11 0011.
 */

public class SharesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private List<Shares> data=new ArrayList<>();
    private OnRecyclerViewListener onRecyclerViewListener;

    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    //更新列表
    public void setData(List<Shares> data) {
        this.data.clear();
        if(data!=null){
            this.data.addAll(data);
        }
        notifyDataSetChanged();
    }

    public Shares getItem(int position){
        return this.data == null?null:(position >= this.data.size()?null:this.data.get(position));
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new FileViewHolder(parent.getContext(),parent,onRecyclerViewListener);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        //绑定数据
        ((BaseViewHolder)holder).bindData(data.get(position));
    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }
}

